﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using GdHotel.Data.Interfaces;
using GdHotel.Data.Repositories;
using GdHotel.Web.Attributes;
using GdHotel.Web.Models;
using UniqueTechnologies.Attributes;
using UniqueTechnologies.Data.Interfaces;

namespace GdHotel.Web.Controllers
{
    [LayoutSupport]
    [LanguageSupport]
    public class ShowPageController : BaseUiController
    {
        public override ILanguagesRepository LanguagesRepository { get; set; }
        public override INotesRepository NotesRepository { get; set; }
        public override IMainMenuItemsRepository MainMenuItemsRepository { get; set; }
        public override IAdditionalMenuItemsRepository AdditionalMenuItemsRepository { get; set; }
        public ICustomPagesRepository CustomPagesRepository { get; set; }
        public IGalleriesRepository GalleriesRepository { get; set; }

        private const String ConferenceKey = "conference";
        private const String ConferenceExtraKey = "conferenceextra";
        private const String CommonKey = "common";

        public ShowPageController(ILanguagesRepository languagesRepository, INotesRepository notesRepository, IMainMenuItemsRepository mainMenuItemsRepository, IAdditionalMenuItemsRepository additionalMenuItemsRepository, ICustomPagesRepository customPagesRepository, IGalleriesRepository galleriesRepository)
        {
            LanguagesRepository = languagesRepository;
            NotesRepository = notesRepository;
            MainMenuItemsRepository = mainMenuItemsRepository;
            AdditionalMenuItemsRepository = additionalMenuItemsRepository;
            CustomPagesRepository = customPagesRepository;
            GalleriesRepository = galleriesRepository;
        }

        //
        // GET: /Show/

        public ActionResult Show(String name)
        {
            var page = CustomPagesRepository.FindAllByLangAndName(Language, name).FirstOrDefault();
            if (page == null)
                return RedirectToAction("Index", "Home");
            var pageGallery = GalleriesRepository.FindAllByKey(CommonKey).FirstOrDefault();
            var gallery = GalleriesRepository.FindAllByKey(page.Key).FirstOrDefault();
            var model = new ShowModel {Page = page, PageGallery = pageGallery, Gallery = gallery };
            return View(model);
        }


        //
        // GET: /Show/Conference

        public ActionResult Conference()
        {
            var page = CustomPagesRepository.FindAllByLangAndKey(Language, ConferenceKey).FirstOrDefault();
            if (page == null)
                return RedirectToAction("Index", "Home");
            var extraPage = CustomPagesRepository.FindAllByLangAndKey(Language, ConferenceExtraKey).FirstOrDefault();
            var pageGallery = GalleriesRepository.FindAllByKey(CommonKey).FirstOrDefault();
            var gallery = GalleriesRepository.FindAllByKey(ConferenceKey).FirstOrDefault();
            var model = new ShowModel {Page = page, ExtraPage = extraPage, PageGallery = pageGallery, Gallery = gallery};
            return View(model);
        }
    }
}
